﻿#include <gtest/gtest.h>

#include "math/polynomial.h"

using namespace CAGD;

// 测试 Polynomial
TEST(TestPolynomial, BasisFunctions)
{
    // 测试比较
    {
        Polynomial poly({1, 2, 3});
        Polynomial poly2;
        poly2.Add(1);
        poly2.Add(2);
        poly2.Add(3);
        EXPECT_TRUE(poly == poly2);
    }

    // 测试初始化赋值
    {
        Polynomial poly({1, 2, 3});
        Polynomial poly2(poly);
        EXPECT_TRUE(poly == poly2);

        Polynomial poly3;
        poly3 = poly;
        EXPECT_TRUE(poly == poly3);
    }

    // 测试四则运算
    {
        Polynomial poly1({1, 2, 3});
        Polynomial poly2({2, 3, 4});
        Polynomial poly3({2, 7, 16, 17, 12});
        Polynomial poly4({1, 3, 2});
        Polynomial poly5({1, 3, 2, 6});

        EXPECT_TRUE((poly1 + poly5) == Polynomial({2, 5, 5, 6}));
        EXPECT_TRUE((poly5 + poly1) == Polynomial({2, 5, 5, 6}));
        EXPECT_TRUE((poly1 - poly5) == Polynomial({0, -1, 1, -6}));
        EXPECT_TRUE((poly5 - poly1) == Polynomial({0, 1, -1, 6}));

        EXPECT_TRUE((poly1 * poly2) == poly3);
        EXPECT_TRUE((poly3 / poly4) == Polynomial({23.0 / 4, -0.5, 6}));

        EXPECT_TRUE((poly1 * 1.5) == Polynomial({1.5, 3, 4.5}));
        EXPECT_TRUE((poly1 / 2) == Polynomial({0.5, 1, 1.5}));
    }

    // 测试求导和积分
    {
        Polynomial poly1({1, 2, 3, 4});
        Polynomial poly2({2, 6, 12});
        Polynomial poly3({0, 1, 1, 1, 1});

        EXPECT_DOUBLE_EQ(poly1.Value(2), 49);
        EXPECT_TRUE(poly1.Derivative() == poly2);
        EXPECT_TRUE(poly1.Intergral() == poly3);
        EXPECT_DOUBLE_EQ(poly1.Intergral(1, 2), 26);
    }
}

// 测试 PwPolynomial
TEST(TestPwPolynomial, BasisFunctions)
{
}

// 测试多项式算法
TEST(TestPolynomial, Algorithm)
{
}

// 测试分段多项式算法
TEST(TestPwPolynomial, Algorithm)
{
}